#include "aes.h"
void aes_cfb128_encrypt(in, out, length, schedule, ivec, num, encrypt)
     unsigned char *in;
     unsigned char *out;
     long length;
     aes_context  *schedule;
     unsigned char *ivec;
     int *num;
     int encrypt;
{
     register int n=*num;
     register long l=length;
     unsigned char c,cc;
     unsigned char iv1[16];
     if(encrypt){
        while(l--){
           if(n==0){
               aes_encrypt(schedule,ivec,iv1);
                   }
            c=*(in++)^iv1[n];
            *(out++)=c;
            ivec[n]=c;
            n=(n+1)&0x0f;
                   }
    } else{
           while(l--){
                       if(n==0){
                          aes_encrypt(schedule,ivec,iv1);
                               }
                       cc=*(in++);
                       c=iv1[n];
                       ivec[n]=cc;
                       *(out++)=c^cc;
                       n=(n+1)&0x0f;
                     } 

           }
   c=cc=0;
   *num=n;
}
